﻿using System;
using System.Collections.Generic;
using NHibernate;
using ParaEditor.Common.NHibernate;
using ParaEditor.Domain.Entities;

namespace ParaEditor.DAO.Thread
{
    public class BatchObject
    {
        protected static ISession Session { get; set; }

        public IList<Para4030> objList;
        public BatchObject(IList<Para4030> list)
        {
            NHibernateMemberNonSingleton member = new NHibernateMemberNonSingleton();
            objList = list;
            Session = member.GetSession();
        }

        public void BatchCreateObject(IList<Para4030> objs)
        {
            try
            {
                int count = objs.Count;
                for (int i = 1; i < count + 1; i++)
                {
                    Session.Merge(objs[i - 1]);
                    if (i % 500 == 0)
                    {
                        Session.Flush();
                        Session.Clear();
                    }
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                Session.Flush();
                Session.Clear();
            }
        }
    }
}
